from fastapi import FastAPI
import uvicorn

from tortoise.contrib.fastapi import register_tortoise
from settings import TORTOISE_CONFIG

from api.course import course
from api.student import student

from models import *

from fastapi.templating import Jinja2Templates
from fastapi import Request

app = FastAPI()

register_tortoise(
    app,
    config=TORTOISE_CONFIG
)

app.include_router(course, prefix="/course", tags=["课程管理", ])
app.include_router(student, prefix="/student", tags=["学生管理", ])


@app.get("/")
async def index(request: Request):
    templates = Jinja2Templates(directory="templates")
    students = await Student.all()
    return templates.TemplateResponse("index.html", {
        "request": request,
        "students": students
    })


if __name__ == "__main__":
    uvicorn.run("main:app", host="127.0.0.1", port=8000, reload=True)
